package com.travel.controller;

import com.travel.pojo.ScenicSpot;
import com.travel.service.impl.HomePageServiceImpl;
import com.travel.util.Result;
import com.travel.util.SteamUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.CrossOrigin;

@RestController
public class HomePageController {
    @Autowired
    private HomePageServiceImpl homePageService;
//    查询景点以及景点对应的城市
    @GetMapping("/homePage/select")
    public Result selectAll(){
        List<ScenicSpot> list = homePageService.listBySName();
        List<Map<String, Object>> maps = new ArrayList<>();
        for (ScenicSpot scenicSpot : list) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", scenicSpot.getId());
            map.put("sName", scenicSpot.getSName());
            map.put("cityId", scenicSpot.getCityId());
            byte[] img = scenicSpot.getSImg();
            String base64Img = SteamUtil.writeSteamImg(img);
            map.put("base64Img", base64Img);
            maps.add(map);
        }
        return new Result<>("查询成功", 200, maps);
    }
//    展示首页宣传视频
//    @CrossOrigin(origins = "http://127.0.0.1:5500")
//    微信小程序视频的特殊性不允许使用base64进行转换也不允许使用本地视频,只能使用资源视频,
//    这里是转换成功能在h5展示,但是不能在微信小程序中展示
    @GetMapping("/homePage/selectVideo")
    public Result listVideo(){
        String base64 = SteamUtil.convertRemoteVideoToBase64("https://vdept3.bdstatic.com/mda-qacr3gihc5wpb4wu/360p/h264/1705167795574224469/mda-qacr3gihc5wpb4wu.mp4?v_from_s=hkapp-haokan-hnb&auth_key=1717454725-0-0-9e469ae7b1b8409bcac1e32a6798e1cf&bcevod_channel=searchbox_feed&pd=1&cr=0&cd=0&pt=3&logid=2725815992&vid=2776927846740632320&klogid=2725815992&abtest=");
        return new Result<>(base64,200);
    }
}
